package com.base.cn.platform.os.controller.classes.topic.report;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.common.classes.TeacherDataIsolation;
import com.base.cn.platform.os.common.log.aop.AdminModuleEnum;
import com.base.cn.platform.os.common.log.aop.OpLog;
import com.base.cn.platform.os.service.course.classes.topic.report.ClassesTopicReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * 话题举报
 *
 * @author SK
 * @since 2018-06-05
 */
@Controller
@RequestMapping("/admin/classes/topic")
public class AdminClassesTopicReportController extends AdminBaseController {

    @Autowired
    private ClassesTopicReportService classesTopicReportService;

    /**
     * 初始化班级话题举报列表页面
     *
     * @return 班级话题举报列表页面
     */
    @RequestMapping("/topicReportList")
    public String topicReportList() {
        return resultPage("/classes/topic/report/topic-report-list");
    }

    /**
     * 班级话题举报列表页面
     *
     * @param params 话题举报查询参数
     * @return 班级话题举报列表页面
     */
    @RequestMapping("/ajaxTopicReportList")
    @TeacherDataIsolation(type=4)
    public String ajaxTopicReportList(Model model,
                                      @RequestBody Map<String, Object> params,
                                      @RequestParam(value = "currentPage", required = false, defaultValue = "1") Integer currentPage) {
        Object title = params.remove("title");
        Object content = params.remove("content");
        Map<String, Object> classesTopic = new HashMap<>();
        classesTopic.put("title", title);
        classesTopic.put("content", content);
        params.put("classesTopic", classesTopic);
        Object keyword = params.remove("keyword");
        params.put("user", Collections.singletonMap("keyWord", keyword));
        Map<String, Object> dataMap = classesTopicReportService.findClassesTopicReportPage(params, currentPage);
        model.addAttribute("dataMap", dataMap);
        return resultPage("/classes/topic/report/ajax-topic-report-list");
    }

    /**
     * 更新话题举报状态
     *
     * @param ids    话题举报id
     * @param status 1.正常 2.删除
     * @return 操作结果
     */
    @RequestMapping("/updateTopicReportStatus")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.OTHER, action = "更新被举报话题状态")
    public Map<String, Object> updateTopicReportStatus(@RequestParam("ids") String ids,
                                                       @RequestParam("status") Integer status) {
        return classesTopicReportService.updateClassesTopicReportStatus(ids, status);
    }
}
